package com.chixing.controller;

import com.chixing.pojo.Member;
import com.chixing.service.MemberService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class MemberController {

    @Autowired
    private MemberService memberService;

    @GetMapping("member/{id}")
    @ResponseBody
    public Member getById(@PathVariable("id") Integer id){
        System.out.println("controller getById:" + id);
        Member member = memberService.getById(id);
        return member;
    }

    @GetMapping("member")
    @ResponseBody
    public List<Member> getAll(){
        System.out.println("controller getAll");
        List<Member> memberList =memberService.getAll();
        return memberList;
    }

    @PostMapping("member")
    @ResponseBody
    public boolean save(Member member){
        System.out.println("controller save:" + member);
        boolean result = memberService.save(member);
        return result;
    }

    @DeleteMapping("member/{id}")
    @ResponseBody
    public boolean delete(@PathVariable("id") Integer id){
        System.out.println("controller delete:" + id);
        boolean result = memberService.delete(id);
        return result;
    }

    @GetMapping("member/page/{pagenum}")
    @ResponseBody
    public PageInfo<Member> getByPage(@PathVariable("pagenum") Integer pageNum){
        return memberService.getByPage(pageNum);
    }

}
